package com.bracelet.schedule;


import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.client.RestTemplate;

/*
* 批处理类定时获取各类设备信息
* */
@Component
@EnableScheduling
@Slf4j
@Controller
public class BatchSchedule {
    @Value("${schedule.url}")
    String url;

    @Scheduled(cron = "${schedule.cronjob.heartrate}")
    @GetMapping("getHeartRate")
    public void getHeartRate(){
        log.info("定时获取【心率】任务开始");
        String key = url+"heartrate";
        RestTemplate restTemplate = new RestTemplate();
        ObjectMapper mapper = new ObjectMapper();
        JsonNode node = mapper.createObjectNode().put("args","heartrate");
        ResponseEntity<ObjectNode> response
                = restTemplate.postForEntity(key, node, ObjectNode.class);
    }

    @Scheduled(cron = "${schedule.cronjob.bodytemperature}")
    public void getBodyTemperature(){
        log.info("定时获取【体温】任务开始");
        String key = url+"bodytemperature";
        RestTemplate restTemplate = new RestTemplate();
        ObjectMapper mapper = new ObjectMapper();
        JsonNode node = mapper.createObjectNode().put("args","bodytemperature");
        ResponseEntity<ObjectNode> response
                = restTemplate.postForEntity(key, node, ObjectNode.class);
    }

    @Scheduled(cron = "${schedule.cronjob.bloodpressure}")
    public void bloodPressure(){
        log.info("定时获取【血压】任务开始");
        String key = url+"bloodpressure";
        RestTemplate restTemplate = new RestTemplate();
        ObjectMapper mapper = new ObjectMapper();
        JsonNode node = mapper.createObjectNode().put("args","bloodpressure");
        ResponseEntity<ObjectNode> response
                = restTemplate.postForEntity(key, node, ObjectNode.class);
    }

    @Scheduled(cron = "${schedule.cronjob.bloodoxygen}")
    public void getBloodOxygen(){
        log.info("定时获取【血氧】任务开始");
        String key = url+"bloodoxygen";
        RestTemplate restTemplate = new RestTemplate();
        ObjectMapper mapper = new ObjectMapper();
        JsonNode node = mapper.createObjectNode().put("args","bloodoxygen");
        ResponseEntity<ObjectNode> response
                = restTemplate.postForEntity(key, node, ObjectNode.class);
    }



}
